<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2024/2/27 0027
 * Time: 9:57
 */

namespace app\admin\model;


use think\Model;

class AuthRule extends Model
{
    /**
     * 获取规则列表
     * @param int $menu
     * @param int $status
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getList($menu = 1, $status = 1)
    {
        if ($menu == 1) {
            $this->where("menu", 1);
        }
        if ($status == 1) {
            $this->where("status", 1);
        }
        return $this->order('sort', 'asc')->selectOrFail()->toArray();
    }

    /**
     * 获取一条数据
     * @param $id
     * @return array
     */
    public function getOneById($id)
    {
        return $this->where("id", $id)->findOrEmpty()->toArray();
    }

    /**
     * 添加
     * @param $data
     * @return int|string
     */
    public function add($data)
    {
        return $this->insert($data);
    }

    public function edit($id, $data)
    {
        return $this->where("id", $id)->update($data);
    }

    public function del($id)
    {
        return $this->where("id", $id)->delete();
    }

    public function getChildrenRule($id)
    {
        return $this->where("pid", $id)->findOrEmpty()->toArray();
    }
}